var api = require('../../../../api.js');
var utils = require('../../../../utils.js');
var app = getApp();
// pages/integral/okorder/okorder.js
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    // 立即兑换 
    exchangebtn: function () {
        var that = this
        let id_index = that.data.id_index
        let cat_id = that.data.id_index
        let attr_list = that.data.attr_list
        let address_id = that.data.address_id
        let goods_id = that.data.goods_id
        console.log(address_id)
        console.log("======================")

        app.request({
            url: api.integralmall.submit,
            data: {
                id_index: id_index,
                cat_id: cat_id,
                attr_list: attr_list,
                address_id: address_id,
                goods_id: goods_id
            },
            header: {},
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
        })
    },

    clickaddress: function () {
        var that = this
        app.request({
            url: api.user.address_list,
            data: '',
            header: {},
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: function (res) {
                console.log(res.data.list[0].id)
                console.log("=========================")
                that.setData({
                    address: res.data.list[0],
                    address_id: res.data.list[0].id
                })
            },
            fail: function (res) { },
            complete: function (res) { },
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

        var that = this
        var cat_id = options.cat_id
        var id_index = options.id_index
        var attr_list = options.attr_list
        console.log(options)


        that.setData({
            id_index: id_index,
            cat_id: cat_id,
            attr_list: attr_list
        })
        //   禾匠 積分商城 data
        app.request({
            url: api.integralmall.index,
            data: '',
            header: {},
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: function (res) {
                that.setData({
                    simple: res.data.goods_list[cat_id].goods[id_index],
                    // 用户剩余积分
                    user_integral: res.data.user.integral,
                    // 商品积分
                    shop_integral: res.data.goods_list[cat_id].goods[id_index].integral,
                    // shop id
                    goods_id: res.data.goods_list[cat_id].goods[id_index].id
                })
            },
            fail: function (res) { },
            complete: function (res) { },
        })
        that.setData({

        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})